/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {boolean}
 */
 var isPalindrome = function(head) {
  if (!head || !head.next) {
      return true;
  }
  let slow = head;
  let fast = head.next;
  while (fast && fast.next) {
      slow = slow.next;
      fast = fast.next.next;
  }
  let cur = slow.next;
  slow.next = null;
  let pre = null;
  while (cur) {
      let t = cur.next;
      cur.next = pre;
      pre = cur;
      cur = t;
  }
  while (pre) {
      if (pre.val !== head.val) {
          return false;
      }
      pre = pre.next;
      head = head.next;
  }
  return true;
};